import type { App } from 'vue'
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"
import { createRouterGuards } from "@/routes/permission"

const routes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/',
    name: 'Layout',
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/home/index.vue')
      }
    ]
  }
]


// 创建路由实例
const router = createRouter({
  routes,
  history: createWebHashHistory(),
  scrollBehavior: () => ({ left: 0, top: 0 })
})

// 将路由挂载到vue实例上的方法
export function setupRouter(app: App<Element>) {
  app.use(router)
  createRouterGuards(router)
}

